package com.ruoyi.match.enums;

import cn.hutool.core.util.StrUtil;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.match.match.domain.Match;
import com.ruoyi.match.match.domain.RealTimeMatch;
import com.ruoyi.match.match.dto.ScorePriceDto;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.apache.commons.compress.utils.Lists;

import java.math.BigDecimal;
import java.util.List;

/**
 * @Author sjz
 * @Date 2023/11/6 14:24
 * @Desc
 */
@Getter
@AllArgsConstructor
public enum ScoreEnum {
    CS_0_1(1,"0:1"),
    CS_0_2(2,"0:2"),
    CS_0_3(3,"0:3"),
    CS_0_4(4,"0:4"),
    CS_0_5(5,"0:5"),

    CS_1_0(1,"1:0"),
    CS_1_2(3,"1:2"),
    CS_1_3(4,"1:3"),
    CS_1_4(5,"1:4"),
    CS_1_5(6,"1:5"),
    CS_2_0(2,"2:0"),
    CS_2_1(3,"2:1"),
    CS_2_3(5,"2:3"),
    CS_2_4(6,"2:4"),
    CS_2_5(7,"2:5"),
    CS_3_0(3,"3:0"),
    CS_3_1(4,"3:1"),
    CS_3_2(5,"3:2"),
    CS_4_0(4,"4:0"),
    CS_4_1(5,"4:1"),
    CS_4_2(6,"4:2"),
    CS_5_0(5,"5:0"),
    CS_5_1(6,"5:1"),
    CS_5_2(7,"5:2"),
    LEVEL_0_0(0,"0:0"),
    LEVEL_1_1(1,"1:1"),
    LEVEL_2_2(2,"2:2"),
    LEVEL_3_3(3,"3:3"),
    LEVEL_OTHER(7,"平其他"),
    WIN_OTHER(8,"胜其他"),
    LOST_OTHER(9,"负其他"),

    ;

    private Integer index;
    private String code;

    public static List<String> getListByIndex(Integer index){
        List<String> result = Lists.newArrayList();
        for (ScoreEnum value : ScoreEnum.values()) {
            if(value.index <= index){
                result.add(value.code);
            }
        }
        return result;
    }

    public static String getMatchResult(ScoreEnum se){
        String result = "";
        for (ScoreEnum value : ScoreEnum.values()) {
            if(se.equals(value)) {
                switch (value) {
                    case CS_0_1:
                    case CS_0_4:
                    case CS_0_5:
                    case CS_0_2:
                    case CS_0_3:
                    case CS_1_2:
                    case CS_1_3:
                    case CS_1_4:
                    case CS_1_5:
                    case CS_2_3:
                    case CS_2_4:
                    case CS_2_5:
                    case LOST_OTHER:
                        result = "客";
                        break;
                    case CS_1_0:
                    case CS_2_0:
                    case CS_2_1:
                    case CS_3_0:
                    case CS_3_1:
                    case CS_3_2:
                    case CS_4_0:
                    case CS_4_1:
                    case CS_4_2:
                    case CS_5_0:
                    case CS_5_1:
                    case CS_5_2:
                    case WIN_OTHER:
                        result = "主";
                        break;
                    case LEVEL_0_0:
                    case LEVEL_1_1:
                    case LEVEL_2_2:
                    case LEVEL_3_3:
                    case LEVEL_OTHER:
                        result = "平";
                        break;
                }
            }
        }
        return result;
    }

    public static ScorePriceDto getScorePriceDto(Match match, String score){
        ScorePriceDto dto = new ScorePriceDto();
        for (ScoreEnum value : ScoreEnum.values()) {
            if(score.equals(value.code)){
                dto.setScore(value.code);
                switch (value){
                    case CS_0_1:
                        dto.setPrice(match.getCs01());
                        break;
                    case CS_0_2:
                        dto.setPrice(match.getCs02());
                        break;
                    case CS_0_3:
                        dto.setPrice(match.getCs03());
                        break;
                    case CS_0_4:
                        dto.setPrice(match.getCs04());
                        break;
                    case CS_0_5:
                        dto.setPrice(match.getCs05());
                        break;
                    case CS_1_0:
                        dto.setPrice(match.getCs10());
                        break;
                    case CS_1_2:
                        dto.setPrice(match.getCs12());
                        break;
                    case CS_1_3:
                        dto.setPrice(match.getCs13());
                        break;
                    case CS_1_4:
                        dto.setPrice(match.getCs14());
                        break;
                    case CS_1_5:
                        dto.setPrice(match.getCs15());
                        break;
                    case CS_2_0:
                        dto.setPrice(match.getCs20());
                        break;
                    case CS_2_1:
                        dto.setPrice(match.getCs21());
                        break;
                    case CS_2_3:
                        dto.setPrice(match.getCs23());
                        break;
                    case CS_2_4:
                        dto.setPrice(match.getCs24());
                        break;
                    case CS_2_5:
                        dto.setPrice(match.getCs25());
                        break;
                    case CS_3_0:
                        dto.setPrice(match.getCs30());
                        break;
                    case CS_3_1:
                        dto.setPrice(match.getCs31());
                        break;
                    case CS_3_2:
                        dto.setPrice(match.getCs32());
                        break;
                    case CS_4_0:
                        dto.setPrice(match.getCs40());
                        break;
                    case CS_4_1:
                        dto.setPrice(match.getCs41());
                        break;
                    case CS_4_2:
                        dto.setPrice(match.getCs42());
                        break;
                    case CS_5_0:
                        dto.setPrice(match.getCs50());
                        break;
                    case CS_5_1:
                        dto.setPrice(match.getCs51());
                        break;
                    case CS_5_2:
                        dto.setPrice(match.getCs52());
                        break;
                    case LEVEL_0_0:
                        dto.setPrice(match.getLevel00());
                        break;
                    case LEVEL_1_1:
                        dto.setPrice(match.getLevel11());
                        break;
                    case LEVEL_2_2:
                        dto.setPrice(match.getLevel22());
                        break;
                    case LEVEL_3_3:
                        dto.setPrice(match.getLevel33());
                        break;
                    case LEVEL_OTHER:
                        dto.setPrice(match.getLevelOther());
                        break;
                    case WIN_OTHER:
                        dto.setPrice(match.getWinOther());
                        break;
                    case LOST_OTHER:
                        dto.setPrice(match.getLostOther());
                        break;
                }
            }else if(match.getMatchResult() == 3){
                dto.setPrice(match.getLevelOther());
            }else if(match.getMatchResult() == 1){
                dto.setPrice(match.getWinOther());
            }else {
                dto.setPrice(match.getLostOther());
            }
            return dto;
        }
        return new ScorePriceDto();
    }

    public static ScorePriceDto getScoreRealPriceDto(RealTimeMatch match, String score) {
        ScorePriceDto dto = new ScorePriceDto();
        for (ScoreEnum value : ScoreEnum.values()) {
            if(score.equals(value.code)){
                dto.setScore(value.code);
                switch (value){
                    case CS_0_1:
                        dto.setPrice(match.getCs01());
                        break;
                    case CS_0_2:
                        dto.setPrice(match.getCs02());
                        break;
                    case CS_0_3:
                        dto.setPrice(match.getCs03());
                        break;
                    case CS_0_4:
                        dto.setPrice(match.getCs04());
                        break;
                    case CS_0_5:
                        dto.setPrice(match.getCs05());
                        break;
                    case CS_1_0:
                        dto.setPrice(match.getCs10());
                        break;
                    case CS_1_2:
                        dto.setPrice(match.getCs12());
                        break;
                    case CS_1_3:
                        dto.setPrice(match.getCs13());
                        break;
                    case CS_1_4:
                        dto.setPrice(match.getCs14());
                        break;
                    case CS_1_5:
                        dto.setPrice(match.getCs15());
                        break;
                    case CS_2_0:
                        dto.setPrice(match.getCs20());
                        break;
                    case CS_2_1:
                        dto.setPrice(match.getCs21());
                        break;
                    case CS_2_3:
                        dto.setPrice(match.getCs23());
                        break;
                    case CS_2_4:
                        dto.setPrice(match.getCs24());
                        break;
                    case CS_2_5:
                        dto.setPrice(match.getCs25());
                        break;
                    case CS_3_0:
                        dto.setPrice(match.getCs30());
                        break;
                    case CS_3_1:
                        dto.setPrice(match.getCs31());
                        break;
                    case CS_3_2:
                        dto.setPrice(match.getCs32());
                        break;
                    case CS_4_0:
                        dto.setPrice(match.getCs40());
                        break;
                    case CS_4_1:
                        dto.setPrice(match.getCs41());
                        break;
                    case CS_4_2:
                        dto.setPrice(match.getCs42());
                        break;
                    case CS_5_0:
                        dto.setPrice(match.getCs50());
                        break;
                    case CS_5_1:
                        dto.setPrice(match.getCs51());
                        break;
                    case CS_5_2:
                        dto.setPrice(match.getCs52());
                        break;
                    case LEVEL_0_0:
                        dto.setPrice(match.getLevel00());
                        break;
                    case LEVEL_1_1:
                        dto.setPrice(match.getLevel11());
                        break;
                    case LEVEL_2_2:
                        dto.setPrice(match.getLevel22());
                        break;
                    case LEVEL_3_3:
                        dto.setPrice(match.getLevel33());
                        break;
                    case LEVEL_OTHER:
                        dto.setPrice(match.getLevelOther());
                        break;
                    case WIN_OTHER:
                        dto.setPrice(match.getWinOther());
                        break;
                    case LOST_OTHER:
                        dto.setPrice(match.getLostOther());
                        break;
                }
                return dto;
            }
        }
        return null;
    }

    public static ScoreEnum getScoreByMatchScoreResult(String matchScore) {
        for (ScoreEnum value : ScoreEnum.values()) {
            if(value.code.equals(matchScore)){
                return value;
            }
        }
        List<String> split = StrUtil.split(matchScore, ":");
        if(split.size() == 2){
            BigDecimal a = new BigDecimal(split.get(0));
            BigDecimal b = new BigDecimal(split.get(1));
            if(a.compareTo(b) == 0){
                return LEVEL_OTHER;
            }else if(a.compareTo(b) > 0){
                return WIN_OTHER;
            }else {
                return LOST_OTHER;
            }
        }
        return null;
    }



}
